﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace SyncClient_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string host = "127.0.0.1";
            int port = 9999;

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(host, port);

            Console.WriteLine($"客户端地址:{socket.LocalEndPoint.ToString()}");

            // Send
            string str = "hello unity!";
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            socket.Send(bytes);

            // Recv
            byte[] readBuff = new byte[1024];
            int count = socket.Receive(readBuff);
            string recvString = Encoding.UTF8.GetString(readBuff, 0, count);

            Console.WriteLine($"收到服务端 recvString:{recvString}");

            socket.Close();
        }
    }
}
